Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
Simple questions on javasript: socket.io and arrow function method () => {}

I'm currently studying basic javascript features, and I am quite struggling with the arrow function method. So I from what I've learnt, if there is only one parameter, it doesn't matter if we use parenthesis or not like the code below:

(singleParam) => { statements }
singleParam => { statements }

Then when emitting events in socket IO, to simplify the codes

// server-side
io.on("connection", (socket) => {
  socket.emit("hello", "world");
});

// client-side
socket.on("hello", (arg) => {
  console.log(arg); // world
});

could be simplified as

// server-side
io.on("connection", socket => {
  socket.emit("hello", "world");
});

// client-side
socket.on("hello", arg => {
  console.log(arg); // world
});

This is working fine in my project, thus I wonder the necessity of using parenthesis when using arrow method function. Maybe I'm not fully grasping the concepts, can anyone explain this method a little bit easier way? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If using exactly one parameter in an arrow function you don't need to use the parenthesis. Some developers prefer to always add them however for consistency and readability.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda